/**
 ********************************************************************
 * @author roocket
 * @file    file_lock.h
 * @version V0.0.0
 * @date    2024/3/22
 * @brief   This file is to indicate file synchronize functions. 
 * @attention Code file rules:
 * rule: file encoding use UTF8;
 * rule: max line length 120 characters;
 * rule: line separator \r\n;
 * rule: use clion auto code format tool.
 */

#ifndef _FILE_LOCK_H_
#define _FILE_LOCK_H_

#include <sys/time.h>
#include <sys/file.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <time.h>

/* init the key of door with lock */
int file_lock_init_key_of_door(const char *file);

/* try-wait to acquire lock of file */
int file_lock_trywait_acquire(int fd, long lock_type, int (*file_callback)(void *what_to_do), void *what);

/* unlock the file */
int file_lock_unlock_door(int fd);

#endif /* _FILE_LOCK_H_ */

